package com.wsj.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(BaseServiceProperties.class)
@ConditionalOnClass(BaseService.class)
@ConditionalOnProperty(prefix = "base", value = "enabled", matchIfMissing = true)
public class BaseServiceAutoConfiguation {

  @Autowired
  private BaseServiceProperties baseServiceProperties;

  @Bean
  @ConditionalOnMissingBean(BaseService.class)
  public BaseService baseService() {
    BaseService baseService = new BaseService();
    baseService.setMsg(baseServiceProperties.getMsg());
    return baseService;
  }
}
